package com.chaodriod.common.fragment;

import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chaodriod.common.mvp.presenter.BasePresenter;
import com.swbyte.app.mvp.view.BaseView;


/**
 * Created by 72byte on 2018/3/13.
 */
//kotlin BasePresenter 必须明确泛型
abstract public class BaseMvpFragment<P extends BasePresenter> extends BaseFragment implements BaseView {

    protected P mPresenter;

    protected P getPresenter() {
        return null;
    }

    @CallSuper
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mPresenter == null) {
            mPresenter = getPresenter();
        }
        if (mPresenter != null) {
            //kotlin 不允许这么做
            mPresenter.attachView(this);
        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @CallSuper
    public void onDestroyView() {
        if (mPresenter != null) {
            mPresenter.detachView();
        }
        super.onDestroyView();
    }

}